<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zookeeper 节点类型详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .section-divider {
            position: relative;
            text-align: center;
            margin: 3rem 0;
        }
        .section-divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
        }
        .section-divider i {
            position: relative;
            background: white;
            padding: 0 1rem;
            color: #9ca3af;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-network-wired mr-4"></i>Zookeeper 节点类型
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入理解临时节点与持久节点的本质区别</p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-clock mr-2"></i>
                    <span>生命周期管理</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-database mr-2"></i>
                    <span>分布式协调</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-sync-alt mr-2"></i>
                    <span>状态同步</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Zookeeper 中，节点（ZNode）可以分为两种主要类型：临时节点（Ephemeral Nodes）和持久节点（Persistent Nodes）。这两种节点在生命周期、用途和特性上有明显的区别。理解它们的差异对于构建可靠的分布式系统至关重要。
            </p>
        </div>

        <!-- Visual Comparison -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center text-gradient">节点类型对比图</h2>
            <div class="mermaid">
                graph TD
                    A[Zookeeper 节点类型] --> B[临时节点]
                    A --> C[持久节点]
                    
                    B --> B1[与Session绑定]
                    B --> B2[自动删除]
                    B --> B3[状态指示]
                    
                    C --> C1[永久存在]
                    C --> C2[显式删除]
                    C --> C3[配置存储]
                    
                    B1 --> D[客户端断开即删除]
                    B3 --> E[分布式锁/临时数据]
                    
                    C1 --> F[系统重启后保留]
                    C3 --> G[元数据/配置信息]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Ephemeral Nodes Section -->
        <div class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-yellow-500 text-white rounded-full w-16 h-16 flex items-center justify-center mr-4">
                    <i class="fas fa-hourglass-half text-2xl"></i>
                </div>
                <h2 class="text-4xl font-bold text-gray-800">临时节点（Ephemeral Nodes）</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-heartbeat mr-3 feature-icon"></i>
                        定义和生命周期
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div class="flex items-start">
                            <i class="fas fa-link mt-1 mr-3 text-yellow-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">生命周期</h4>
                                <p>临时节点与客户端的 Session 相关联。当客户端与 Zookeeper 的 Session 断开（例如，客户端崩溃或网络故障）时，Zookeeper 会自动删除这些临时节点。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-trash-alt mt-1 mr-3 text-yellow-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">自动删除</h4>
                                <p>如果客户端的 Session 失效，Zookeeper 会自动清理相关的临时节点，确保系统资源不会泄漏。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-lightbulb mr-3 feature-icon"></i>
                        使用场景
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div class="flex items-start">
                            <i class="fas fa-user-check mt-1 mr-3 text-yellow-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">客户端状态指示</h4>
                                <p>表示客户端在某个服务中的活跃状态，客户端断开时自动反映状态变化。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-lock mt-1 mr-3 text-yellow-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">分布式锁</h4>
                                <p>用于锁的持有者标识，持有者断开连接时自动释放锁资源。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-clock mt-1 mr-3 text-yellow-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">临时数据存储</h4>
                                <p>存储执行任务时的临时数据，会话结束时自动清除。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="section-divider">
            <i class="fas fa-exchange-alt text-2xl"></i>
        </div>

        <!-- Persistent Nodes Section -->
        <div class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-green-500 text-white rounded-full w-16 h-16 flex items-center justify-center mr-4">
                    <i class="fas fa-infinity text-2xl"></i>
                </div>
                <h2 class="text-4xl font-bold text-gray-800">持久节点（Persistent Nodes）</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-shield-alt mr-3 feature-icon"></i>
                        定义和生命周期
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div class="flex items-start">
                            <i class="fas fa-infinity mt-1 mr-3 text-green-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">生命周期</h4>
                                <p>持久节点的生命周期与客户端的 Session 无关。一旦创建，就会一直存在，直到显式地删除它们。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-hand-pointer mt-1 mr-3 text-green-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">显式删除</h4>
                                <p>需要通过显式的删除操作来移除，不会因为客户端的 Session 失效而自动删除。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-cogs mr-3 feature-icon"></i>
                        使用场景
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div class="flex items-start">
                            <i class="fas fa-sliders-h mt-1 mr-3 text-green-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">配置存储</h4>
                                <p>存储配置数据或元数据，在系统重启或客户端断开后保持不变。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-database mt-1 mr-3 text-green-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">持久状态</h4>
                                <p>保存需要持久化的系统全局配置或状态信息。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-sitemap mt-1 mr-3 text-green-500"></i>
                            <div>
                                <h4 class="font-semibold mb-1">节点层次结构</h4>
                                <p>构建目录结构或服务目录，在系统生命周期内长期维持。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Summary Comparison -->
        <div class="bg-gradient-to-r from-purple-500 to-pink-500 rounded-2xl shadow-xl p-8 text-white">
            <h2 class="text-3xl font-bold mb-6 text-center">
                <i class="fas fa-balance-scale mr-3"></i>
                核心差异总结
            </h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white bg-opacity-20 rounded-lg p-4 backdrop-filter backdrop-blur-lg">
                    <h3 class="font-semibol